/*
 * @Author: gavin
 * @Date:   2017-12-21 01:28:05
 * @Last Modified by:   gavin
 * @Last Modified time: 2017-12-25 13:15:43
 */
import React from 'react';
import { Table, Icon, Divider, Button, Card } from 'antd';
import { observer, inject, PropTypes } from 'mobx-react';
import { toJS } from 'mobx';

const columns = [{
  title: 'Title',
  dataIndex: 'title',
}, {
  title: 'ID',
  dataIndex: 'id',
}, {
  title: 'Time',
  dataIndex: 'time',
}];

class Home extends React.Component {
  componentWillMount() {
    if (typeof module !== 'undefined' && module.exports) {
      this.props.backlog.load();
    } else if (this.props.backlog.asJson === undefined || this.props.backlog.asJson.length === 0) {
      // console.log("get data from server");
      this.props.backlog.load();
      // console.log(this.props.backlogs.asJson);
    }
  }

  render() {
    const { backlog } = this.props;
    return (
      <Card>
        <Table columns={columns} dataSource={backlog.asJson} rowKey="id" />
      </Card>
    );
  }
}
Home.propTypes = {
  backlog: PropTypes.observableObject.isRequired,
};
// const ob = observer(Home);
// const inj = inject('news')(ob);
// export default inj;
export default inject('backlog')(observer(Home));
